package com.zyj.java;

/**
 * @program: JVMDemo
 * @ClassName ClassInitTest
 * @author: YaJun
 * @Date: 2021 - 12 - 01 - 11:23
 * @Package: com.zyj.java
 * @Description:
 */
public class ClassInitTest {
    static int num  = 1;

    static {
        num = 2;
        number = 20;
        System.out.println(num);
        // System.out.println(number); // 报错：非法的前向引用 Illegal forward reference
    }

    private static int number = 10; // linking中的prepare: number = 0 --> initial: 20 --> 10
    public static void main(String[] args) {
        System.out.println(ClassInitTest.num);  // 2
        System.out.println(ClassInitTest.number);   // 10
    }

}
